package com.wing.product.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.common.utils.UniqueIdGeneratorUtil;
import com.wing.product.dao.WarehouseMoveInventoryDao;
import com.wing.product.model.entity.WarehouseMoveInventory;
import com.wing.product.model.entity.WarehouseOrder;
import com.wing.product.model.entity.WarehouseProductInventory;
import com.wing.product.model.response.MoveInventoryVO;
import com.wing.product.model.response.WarehouseProductInventoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class WarehouseMoveInventoryServiceImpl extends ServiceImpl<WarehouseMoveInventoryDao, WarehouseMoveInventory> implements WarehouseMoveInventoryService {

    @Autowired
    private WarehouseProductInventoryService warehouseProductInventoryService;

    @Override
    public Page<MoveInventoryVO> list4app(Page pg, Map paramMap) {
        List<MoveInventoryVO> list = baseMapper.list4app(pg, paramMap);
        pg.setRecords(list);
        return pg;
    }

    @Override
    @Transactional
    public Boolean movingInventory(MoveInventoryVO moveInventoryVO) {
        WarehouseMoveInventory warehouseMoveInventory = new WarehouseMoveInventory();
        WarehouseProductInventory warehouseProductInventory=warehouseProductInventoryService.getById(moveInventoryVO.getId());
        warehouseMoveInventory.setInventoryId(warehouseProductInventory.getId());
        warehouseMoveInventory.setWarehouseId(warehouseProductInventory.getWarehouseId());
        warehouseMoveInventory.setWarehouseAreaId(warehouseProductInventory.getWarehouseAreaId());
        warehouseMoveInventory.setWarehouseShelfSpaceId(warehouseProductInventory.getWarehouseShelfSpaceId());
        //2025年7月16日 14:15:19新增移库记录添加现在库位信息
        warehouseMoveInventory.setNowWarehouseId(moveInventoryVO.getWarehouseId());
        warehouseMoveInventory.setNowWarehouseAreaId(moveInventoryVO.getWarehouseAreaId());
        warehouseMoveInventory.setNowWarehouseShelfSpaceId(moveInventoryVO.getWarehouseShelfSpaceId());
        baseMapper.insert(warehouseMoveInventory);

//        WarehouseProductInventory warehouseProductInventory=warehouseProductInventoryService.getById(moveInventoryVO.getId());
        warehouseProductInventory.setWarehouseId(moveInventoryVO.getWarehouseId());
        warehouseProductInventory.setWarehouseAreaId(moveInventoryVO.getWarehouseAreaId());
        warehouseProductInventory.setWarehouseShelfSpaceId(moveInventoryVO.getWarehouseShelfSpaceId());
        warehouseProductInventoryService.updateById (warehouseProductInventory);
        return true;
    }
    // 实现自定义的业务方法
}
